<?php
/**
 * Created by cmb_weixin.master.
 * File: ProfileTemplate.php
 * User: xuewl
 * Date: 2017/12/18
 * Time: 17:07
 */

namespace app\product\model;
use app\common\library\Model;

class ProfileTemplate extends Model
{

    protected $append = ['profile_prop'];
    protected $type = [
        'content' => 'json'
    ];


    function getProfilePropAttr($value, $data) {
        $props = json_decode($data['content'], true);
        $result = [];
        foreach($props as $prop_id => $prop) {
            $result[$prop_id]['name'] = \think\Db::name('form_prop')->where(['id' => $prop_id])->value('name');
            $result[$prop_id]['value'] = \think\Db::name('form_propvalue')->where(['id' => ['in', $prop]])->select();
        }
        return $result;
    }

    function product() {
        return $this->hasOne('app\\product\\model\\Product', 'id', 'product_id');
    }

    function ownerUserInfo() {
        return $this->hasOne("app\\user\\model\\User", 'id', 'owner_aid');
    }

}
